package com.airticketbooking.controller.manager;

import com.airticketbooking.common.domain.R;
import com.airticketbooking.dto.RangeTimeDTO;
import com.airticketbooking.po.OrderStatistics;
import com.airticketbooking.po.UserStatistics;
import com.airticketbooking.service.DataStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
/**
 * @author Mr.J
 * @version 1.0.0
 * @Date 2024/12/21
 * @desc
 */

@RestController
@RequiredArgsConstructor
@Api(tags = "数据统计")
@RequestMapping("/air/manager/dataStatistics")
public class DataStatisticsController {


	private final DataStatisticsService dataStatisticsService;

//	统计本月订单情况,包括了具体的订单数量、总金额等信息

	@ApiOperation(value = "统计订单情况")
	@PostMapping("/orderStatistics")
	public R<OrderStatistics> getOrderStatistics(
			@RequestBody RangeTimeDTO rangeTimeDTO
			) {

		Date startTime = rangeTimeDTO.getStartTime();
		Date endTime = rangeTimeDTO.getEndTime();

		try {
			OrderStatistics orderStatistics = dataStatisticsService.getOrderStatistics(startTime, endTime);
			return R.ok(orderStatistics);
		} catch (Exception e) {
			return R.error(e.getMessage());
		}
	}


//	统计用户情况，以及会员的注册情况、充值情况、消费情况等信息

	@ApiOperation(value = "统计用户情况")
	@PostMapping("/userStatistics")
	public R<UserStatistics> getUserStatistics(

			@RequestBody RangeTimeDTO rangeTimeDTO


	) {
		Date startTime = rangeTimeDTO.getStartTime();
		Date endTime = rangeTimeDTO.getEndTime();

		UserStatistics userStatistics = dataStatisticsService.getUserStatistics(
				startTime,
				endTime
		);

		return R.ok(userStatistics);
	}

}
